
// 162.寻找峰值
class Solution {
public:
    int findPeakElement(vector<int>& nums) {
        // 使用二分来找这个下标
        int n = nums.size() , l = 0 , r = n + 1;
        if(n == 1) return 0;
        nums.insert(nums.begin() , INT_MIN);
        nums.push_back(INT_MIN);
        while(l + 1 < r)
        {
            int mid = l + (r - l)/2;
            if(nums[mid + 1] >= nums[mid]) l = mid;
            else if(nums[mid - 1] >= nums[mid]) r = mid;
            else return mid - 1;
        }
        return -1;
    } 
};